import collections
class Solution(object):
    def interchangeableRectangles(self, rectangles):
        d = collections.defaultdict(int)
        for x, y in rectangles:
            d[x / y] += 1
        ans = 0
        for key in d:
            ans += d[key] * (d[key] - 1) // 2
        return ans
